package com.eedi.framework.tenant.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupBasicReq;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupBasicResp;
import com.eedi.framework.tenant.service.SysSetupBasicService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import static com.eedi.framework.common.pojo.CommonResult.success;

/**
 * 系统界面 - 基本设置
 * @author zybourn
 */
@Tag(name = "系统界面 - 基本设置")
@RestController
@RequestMapping("/setup/basic")
public class SysSetupBasicController {

    @Resource
    SysSetupBasicService sysSetupBasicService;

    @GetMapping("/get")
    @Operation(summary = "获得当前租户的系统设置")
    @PermitAll
    public CommonResult<SysSetupBasicResp> getSysSetupBasic() {
        return success(sysSetupBasicService.getSysSetupBasic());
    }


    @PostMapping("/setup")
    @Operation(summary = "设置当前租户的系统设置")
    @PreAuthorize("@sys.hasPermission('sys:setup:basic-setup')")
    public CommonResult<Void> setup(@RequestBody SysSetupBasicReq req) {
        sysSetupBasicService.setup(req);
        return success(null);
    }

}
